import { Broker } from "./Broker";
import { Publisher } from "./Publisher";
import { Subscriber } from "./Subscriber";

// 创建一个中间人
const broker = new Broker();

// 创建一个发布者
const publisher = new Publisher(broker);   

// 创建四个订阅者
const subscriber1 = new Subscriber(1, broker);
const subscriber2 = new Subscriber(2, broker);
const subscriber3 = new Subscriber(3, broker);
const subscriber4 = new Subscriber(4, broker);

// 这四个订阅者订阅的主题是不一样的
subscriber1.subscribe("动作片");
subscriber2.subscribe("动作片");
subscriber3.subscribe("恐怖片");
subscriber4.subscribe("恐怖片");

publisher.publish("恐怖片", "恐怖片上映了");

subscriber3.unsubscribe("恐怖片");

publisher.publish("恐怖片", "咒怨终结版上映了");
